package work;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

//对sort.txt进行排序

public class homework05 {
	public static void main(String[] args) throws Exception {
		FileInputStream file = new FileInputStream("sort.txt");
		BufferedInputStream in = new BufferedInputStream(file);
		InputStreamReader isr = new InputStreamReader(in,"utf-8");
		BufferedReader br = new BufferedReader(isr);
		
		String line;
		Map<String, String> map = new HashMap<String, String>();
		ArrayList<String> list =new ArrayList<>();
		while((line=br.readLine())!=null){
			String key=line.split("\\.")[0];
			map.put(key, line);
		}
		map.keySet().stream().sorted().forEach(s->{
			list.add(map.get(s));
		});
		FileWriter file1 = new FileWriter("sort.txt");
		BufferedWriter bw = new BufferedWriter(file1);
		for (String c : list) {
			bw.write(c);
			bw.newLine();
		}
		br.close();
		bw.close();
	}
}
